package com.lagou.controller;

import com.alibaba.fastjson.JSONObject;
import com.lagou.WebDemoApplication;
import com.lagou.service.ConsumerComponent;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zjy
 * @date: 2020/5/4 10:42 下午
 */
@RestController
public class DemoController {


    @Autowired
    ConsumerComponent consumerComponent;

    @GetMapping("/demo/hello")
    public JSONObject demo(HttpServletRequest request){

        JSONObject json = new JSONObject();
        RpcContext context = RpcContext.getContext();
        context.setRemoteAddress( request.getRemoteHost(),request.getRemotePort());
        String hello = consumerComponent.sayHello("world", 0);
        System.out.println("result :" + hello);

        json.put("result",hello);

        return json;

    }

}
